Skip to content

fix(openai-agents): properly serialize tool calls in output messages (#4185)#2

Closed
nagkumar91 wants to merge 1 commit into
mainfrom
fix/4185-tool-calls-output
Closed

fix(openai-agents): properly serialize tool calls in output messages (#4185)#2
nagkumar91 wants to merge 1 commit into
mainfrom
fix/4185-tool-calls-output

Conversation

@nagkumar91

Copy link
Copy Markdown
Owner

Summary

Fixes open-telemetry#4185: Tool calls show in output as text with ResponseFunctionToolCall().

Problem

In _normalize_output_messages_to_role_parts(), when handling ResponseSpanData, the code iterates over response.output items. Both ResponseFunctionToolCall objects (which have .arguments, .call_id, .name) and ResponseOutputMessage objects (whose .content is a list of sub-items, not a plain string) were falling through to the str(item) fallback and being rendered as type: "text" with ugly repr strings.

Fix

  • ResponseFunctionToolCall items (detected by type=="function_call" or duck-typing) are now emitted as type: "tool_call" parts with id, name, and arguments fields, per GenAI semantic conventions.
  • ResponseOutputMessage items (detected by type=="message" or list-typed .content) now correctly iterate over their content sub-items to extract text.
  • Existing fallback behavior for plain string content and other item types is preserved.

Tests

Added two new unit tests:

  • test_normalize_output_messages_tool_call_and_message: Verifies both tool call and message items are properly serialized with correct types and content.
  • test_normalize_output_messages_tool_call_redacted: Verifies tool call arguments are redacted when include_sensitive_data is False.

…pen-telemetry#4185)

ResponseFunctionToolCall objects in response.output were being
stringified as text parts. Now detects tool call items by type
attribute and emits them as type:tool_call with id, name, and
arguments per GenAI semantic conventions.

Also handles ResponseOutputMessage objects whose content is a list
of sub-items rather than a plain string.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@nagkumar91 nagkumar91 force-pushed the fix/4185-tool-calls-output branch from f4c086c to ec80276 Compare March 3, 2026 17:50
@nagkumar91 nagkumar91 closed this Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[OpenAI Agents] Tool calls show in output as text with ResponseFunctionToolCall()

1 participant